package javase.javase01.exercise06;

import java.io.*;
import java.util.Arrays;

/**
 * @author: Gan
 * @date 2021/4/17 0017 13:45
 * @description: 1.在一个磁盘的文件里保存26个英文小写字母（乱序），将他们读入内存中，
 * 进行排序，把排好顺序的数再重新追加写到磁盘的该文件中。
 **/
public class work1 {
    public static void main(String[] args) throws IOException {
        FileReader fis = new FileReader("a.txt");
        FileWriter fos = new FileWriter("a.txt", true);
        BufferedReader bufferedReader = new BufferedReader(fis);
        BufferedWriter bufferedWriter = new BufferedWriter(fos);
        char[] chars = new char[1024];
        int readCount;
        while ((readCount = fis.read(chars)) != -1) {
            String s = new String(chars, 0, readCount);
            char[] chars1 = s.toCharArray();
            Arrays.sort(chars1);
            //换行
            bufferedWriter.newLine();
            bufferedWriter.write(chars1, 0, readCount);
        }

        bufferedReader.close();
        bufferedWriter.close();
    }
}
